<%--
  Created by IntelliJ IDEA.
  User: ChadZhao
  Date: 12-2-1
  Time: 下午1:56
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>文章录入</title>
    <style type="text/css">
        body,td,th {
            font-size: 14px;
            color: #666666;
        }
        .form { width:99%; padding:5px;}
        .form th { text-align:right; font-weight:bold; padding:5px;}
        .form td { text-align:left; padding:5px;}
        .listinput { border:1px solid #ccc; padding:3px; background-image:url(<c:url value='/images/listinputbg.gif'/>); width:200px;height:24px;}
        .select1  { border:1px solid #ccc; padding:3px;}
        .button { background-image:url(<c:url value='/images/butbg.gif'/>); height:30px; line-height:30px; color:#FFFFFF; font-weight:bold; border:0px; cursor:hand;}
    </style>
</head>
<body>
		<form method="post" enctype="multipart/form-data">
			<table width="825" border="1" cellpadding="0" cellspacing="0" bordercolor="gray" style="border-collapse:collapse;">
                <tr style="height:28px;">
                    <th>标题</th>
                    <td style="padding-left: 10px;"><s:textfield theme="simple" name="articleTitle" id="articleTitle" cssClass="listinput" maxLength="50" cssStyle="width:300px;"/></td>
                </tr>
                <tr>
                    <th>所属版块</th>
                    <td style="padding-left: 10px;"><p style="font-weight: bold;margin-bottom: 0px;">信息宣传：</p>
                        <input type="checkbox" name="articleType" id="articleType1" value="1"/>廉政头条
                        <input type="checkbox" name="articleType" id="articleType2" value="2"/>图片新闻
                        <input type="checkbox" name="articleType" id="articleType3" value="3"/>要闻速递
                        <input type="checkbox" name="articleType" id="articleType4" value="4"/>廉情动态
                        <input type="checkbox" name="articleType" id="articleType5" value="5"/>年度工作
                        <input type="checkbox" name="articleType" id="articleType7" value="7"/>公告平台
                        <p style="font-weight: bold;margin-bottom: 0px;">互动交流：</p>
                        <input type="checkbox" name="articleType" id="articleType40" value="40"/>专题交流
                        <input type="checkbox" name="articleType" id="articleType41" value="41"/>热点讨论
                        <p style="font-weight: bold;margin-bottom: 0px;">廉政大讲堂：</p>
                        <input type="checkbox" name="articleType" id="articleType8" value="8"/>图片新闻
                        <input type="checkbox" name="articleType" id="articleType10" value="10"/>教育视线
                        <input type="checkbox" name="articleType" id="articleType14" value="14"/>经验推广
                        正反典型:
                        <span style="font-size:9pt;">
                        <input type="checkbox" name="articleType" id="articleType12" value="12"/>勤廉风采
                        <input type="checkbox" name="articleType" id="articleType38" value="38"/>案件聚焦
                            </span><br>
                        <input type="checkbox" name="articleType" id="articleType9" value="9"/>教育计划
                        <input type="checkbox" name="articleType" id="articleType11" value="11"/>文化展厅
                        <input type="checkbox" name="articleType" id="articleType6" value="6"/>他山之石
                        <p style="font-weight: bold;margin-bottom: 0px;">廉政建设：</p>
                        政策法规
                        <span style="font-size:9pt;">
                        <input type="checkbox" name="articleType" id="articleType19" value="19"/>综合篇
                        <input type="checkbox" name="articleType" id="articleType20" value="20"/>教育篇
                        <input type="checkbox" name="articleType" id="articleType21" value="21"/>制度篇
                        <input type="checkbox" name="articleType" id="articleType22" value="22"/>监督篇
                        <input type="checkbox" name="articleType" id="articleType23" value="23"/>惩治篇
                        <input type="checkbox" name="articleType" id="articleType24" value="24"/>预防篇
                        <input type="checkbox" name="articleType" id="articleType25" value="25"/>纠风篇
                            </span><br>
                        <input type="checkbox" name="articleType" id="articleType16" value="16"/>两权监督
                        <input type="checkbox" name="articleType" id="articleType17" value="17"/>政风行风
                        <input type="checkbox" name="articleType" id="articleType18" value="18"/>成果展示
                        <p style="font-weight: bold;margin-bottom: 0px;">廉政文化：</p>
                        文化书架
                        <span style="font-size:9pt;">
                        <input type="checkbox" name="articleType" id="articleType26" value="26"/>清风书苑
                        <input type="checkbox" name="articleType" id="articleType27" value="27"/>格言警句
                        <input type="checkbox" name="articleType" id="articleType28" value="28"/>廉政画册
                        <input type="checkbox" name="articleType" id="articleType29" value="29"/>廉政书法
                        <input type="checkbox" name="articleType" id="articleType39" value="39"/>清风税廉
                            </span><br>
                        <input type="checkbox" name="articleType" id="articleType30" value="30"/>廉政漫画<br>
                </td>
                </tr>
                <tr>
                    <th>摘要<br>(100字以内)</th>
                    <td style="padding:6px 0px 6px 10px;">
                        <s:textarea cols="80" id="summary" name="summary" rows="6" theme="simple" onblur="cutword(this,100)"></s:textarea>
                    </td>
                </tr>
                <tr>
                    <th>内容</th>
                    <td style="padding:6px 0px 6px 10px;">
                        <s:textarea cols="80" id="contextTextArea" name="contextArea" rows="10" theme="simple" cssStyle="display: none;"></s:textarea>
                        <iframe name="myiframe" id="myiframe" src='<c:url value="/Edit/editor.htm?id=contextTextArea&ReadCookie=0"/>'
                                    frameborder="0" scrolling="no" width="820" height="460"></iframe>
                    </td>
                </tr>
                <tr>
                    <th>附件</th>
                    <td style="padding:6px 0px 6px 10px;">
                    <s:if test="attachList!=null">
                        <table cellpadding="0" cellspacing="0" style="width:98%;">
                        <s:iterator value="attachList" id="al" status="alstat">
                            <tr id="tr<s:property value="#al.ATTACHID"/>">
                                <td style="height:22px;width:45%">
                                	<a href="<c:url value="/downloadAttach.do?fileId="/><s:property value="#al.ATTACHID"/>" target="downframe" style="text-decoration:none;font-size:10.5pt;"><s:property value="#al.ATTACHNAME"/></a>
                                </td>
                                <td style="padding-left: 8px;">
                                    <a href="javascript:delAttachFile('<s:property value="#al.ATTACHID"/>')" style="text-decoration:none;font-size:10.5pt;">[删除]</a>
                                </td>
                            </tr>
                        </s:iterator>
                        </table>
                    </s:if>
                        <span id="attspan">
                            <input type="file" name="uploads" id="uploads1" onchange='getAttachname(this)' style="width:300px;"/><label id="label1">名称：</label><input type="text" name="attachname" id="attachname1" class="listinput" style="width:150px;"/><a href="javascript:void(0);" id="dela1" style="text-decoration:none;margin-left:20px;" onclick="delAttach('1')">[删除]</a><br id='br1' style="line-height:10px;">
                        </span>
                        <a href="javascript:void(0);" id="addatta" onclick="addAttach()" style="text-decoration:none;">[添加附件]</a>
                    </td>
                </tr>
                <s:if test="checkComment!=null || dataType==\"2\"">
                <tr>
                    <th>审核意见</th>
                    <td style="padding:6px 0px 6px 10px;">
                        <s:if test="dataType==\"2\"">
                        <s:textarea cols="80" id="checkCommentArea" name="checkComment" rows="6" theme="simple" onblur="cutword(this,500)"></s:textarea>
                        </s:if>
                        <s:else>
                            <s:property value="checkComment" escape="false"/>
                        </s:else>
                    </td>
                </tr>
                </s:if>
                <tr>
                    <td colspan="2" align="center" style="padding:6px 0px 6px 0px;">
                        <s:if test="dataType==\"2\"">
                            &nbsp;
                            <button type="button" class="button" onClick="passCheck('1')">审核通过</button>
                            &nbsp;
                            <button type="button" class="button" onClick="passCheck('2')">审核不通过</button>
                            &nbsp;
                        </s:if>
                        <s:else>
                            <button type="button" class="button" id="savebt" style="width:50px;" onclick="dosave()">保存</button>&nbsp;
                        </s:else>
                        <button type="button" class="button" style="width:50px;" onclick="window.history.back(-1)">返回</button>
                    </td>
                </tr>
            </table>
            <s:hidden name="articleId"/>
            <s:hidden name="partType"/>
            <s:hidden name="dataType"/>
      <div id="upfilediv" style="position:absolute;top:0px;left:0px;text-align:center;filter:alpha(opacity=60);opacity:0.6;background-color:#000000;z-index:2;display:none;">
          <img src="<c:url value='/images/waiting.gif'/>"/> <p style="color:#FFFFFF;">上传中请稍候……</p>
      </div>
            <iframe name="delframe" id="delframe" style="display: none;"></iframe>
<iframe name="downframe" id="downframe" style="display:none;"></iframe>
		</form>
	</body>
<script type="text/javascript">
    parent._setHeight();
    
    var types = document.getElementById("partType").value;
    if(types != "" && types != "0") {
        var tss = types.split(",");
        for (var a = 0; a < tss.length; a ++) {
            document.getElementById("articleType"+tss[a]).checked = true;
        }
    }

    function cutword(obj,leng) {
        var summ = obj.value;
        if(summ.length > leng) {
            obj.value = summ.substring(0,leng);
        }
    }

    function delAttachFile(fileId) {
        if(!confirm("您确认删除该附件吗？该操作不可逆")) return;
        document.forms[0].target="delframe";
        document.forms[0].action="<c:url value='/system/delAttachFile.do?fileId='/>"+fileId;
        document.forms[0].submit();
    }

    function passCheck(rr) {
        if(rr=='2' && document.getElementById("checkCommentArea").value=="") {
            alert("请输入审核意见以便录入人员修改！");
            return;
        }
        if (document.getElementById("articleTitle").value == "") {
            alert("请输入标题！");
            return;
        }
        var haveCheck = false;
        for (var a = 0; a < document.all.articleType.length; a ++) {
            if (document.all.articleType[a].checked) {
                haveCheck = true;
            }
        }
        if (!haveCheck) {
            alert("请选择所属版块！");
            return;
        }
        if (document.frames["myiframe"].getHTML() == "") {
            alert("请输入内容！");
            return;
        }
        if(rr=='2') {
            if(!confirm("您确定不通过本文的审核并退回录入人员吗？")) {
                return;
            }
        } else {
            if(!confirm("您确定通过本文的审核吗？")) {
                return;
            }
        }
        document.forms[0].action="<c:url value='/system/doArticleCheck.do?checkFlag='/>"+rr;
        document.forms[0].submit();
    }

    function delAttach(anum) {
        if(anum=="1") {
            if (document.all.uploads.length && document.all.uploads.length > 1) {
                document.getElementById("uploads"+anum).outerHTML = "";
                document.getElementById("label"+anum).outerHTML = "";
                document.getElementById("attachname"+anum).outerHTML = "";
                document.getElementById("dela"+anum).outerHTML = "";
                document.getElementById("br"+anum).outerHTML = "";
            } else {
                document.getElementById("attspan").innerHTML = "<input type='file' name='uploads' id='uploads1' onchange='getAttachname(this)' style='width:300px;'/>&nbsp;"+
                        "<label id='label1'>名称：</label><input type='text' name='attachname' id='attachname1' class='listinput' style='width:150px;'/>"+
                            "<a href='javascript:void(0);' id='dela1' style='text-decoration:none;margin-left:20px;' onclick='delAttach(\"1\")'>[删除]</a><br id='br1' style='line-height:10px;'>";
            }
        } else {
            document.getElementById("uploads"+anum).outerHTML = "";
            document.getElementById("dela"+anum).outerHTML = "";
            document.getElementById("br"+anum).outerHTML = "";
            document.getElementById("label"+anum).outerHTML = "";
            document.getElementById("attachname"+anum).outerHTML = "";
        }
    }

    function delsuccess(delfileid) {
        alert("删除成功！");
        document.getElementById("tr"+delfileid).parentElement.removeChild(document.getElementById("tr"+delfileid));
    }

    function delfalse() {
        alert("删除失败！");
    }

    function addAttach() {
        var trueorfalse = true;
        var then = 1;
        while(trueorfalse) {
            if(!document.getElementById("uploads"+then)) {
                trueorfalse = false;
                var newfile = document.createElement("<input name='uploads' onchange='getAttachname(this)'>");
                newfile.setAttribute("type", "file");
                newfile.setAttribute("id", "uploads"+then);
//                newfile.onChange= function(){getAttachname(this)};
                newfile.style.width="300px";
                var newlab = document.createElement("label");
                newlab.setAttribute("id", "label"+then);
                newlab.innerText = "名称：";
                var newtext = document.createElement("<input name='attachname'>");
                newtext.setAttribute("type", "text");
                newtext.setAttribute("id", "attachname"+then);
                newtext.style.width="150px";
                newtext.className="listinput";
                var newa = document.createElement("a");
                newa.setAttribute("href", "javascript:delAttach('"+then+"');");
                newa.setAttribute("id", "dela"+then);
                newa.style.textDecoration="none";
                newa.style.marginLeft="20px";
                newa.innerText = "[删除]";
                var newbr = document.createElement("br");
                newbr.style.lineHeight="10px";
                newbr.setAttribute("id", "br"+then);
                document.getElementById("attspan").insertBefore(newfile);
                document.getElementById("attspan").insertBefore(newlab);
                document.getElementById("attspan").insertBefore(newtext);
                document.getElementById("attspan").insertBefore(newa);
                document.getElementById("attspan").insertBefore(newbr);
            }
            then++;
        }
        parent._setHeight();
    }

    function getAttachname(obj) {
        var fullpath = obj.value;
        var fullname = fullpath.substring(fullpath.lastIndexOf("\\")+1,fullpath.lastIndexOf("."));
        var objid = obj.id;
        var objnum = objid.substring(7,objid.length);
        document.getElementById("attachname"+objnum).value = fullname;
    }
    
    function dosave() {
        if (document.getElementById("articleTitle").value == "") {
            alert("请输入标题！");
            return;
        }
        var haveCheck = false;
        for (var a = 0; a < document.all.articleType.length; a ++) {
            if (document.all.articleType[a].checked) {
                haveCheck = true;
            }
        }
        if (!haveCheck) {
            alert("请选择所属版块！");
            return;
        }
        if (document.frames["myiframe"].getHTML() == "") {
            alert("请输入内容！");
            return;
        }
        var attflag = false;
        if(document.all.uploads.length) {
            for(var b = 0;b < document.all.uploads.length;b ++) {
                if(document.all.uploads[b].value!=""){
                    if(document.all.attachname[b].value=="") {
                        alert("请输入附件的名称！");
                        return;
                    } else {
                        attflag = true;
                    }
                } else {
                    var theid = document.all.uploads[b].id;
                    var thenu = theid.substring(7,theid.length);
                    delAttach(thenu);
                }
            }
        } else {
            if(document.all.uploads.value!=""){
                if(document.all.attachname.value=="") {
                    alert("请输入附件的名称！");
                    return;
                } else {
                    attflag = true;
                }
            }
        }
        var mess = "您确定保存该文章吗？";
        if(document.getElementById("summary").value == "") mess = "您没有录入内容摘要，您确定保存吗？";
        if(!confirm(mess)) {
            return;
        }
        if(attflag) {
            document.getElementById("upfilediv").style.height = document.body.scrollHeight+30;
            document.getElementById("upfilediv").style.width = document.body.scrollWidth+30;
            document.getElementById("upfilediv").style.paddingTop = document.body.scrollHeight/2-10;
            document.getElementById("upfilediv").style.display = "block";
        }
        document.getElementById("savebt").disabled = true;
        document.forms[0].action="<c:url value='/system/saveArticleInfo.do'/>";
        document.forms[0].submit();
    }
    var addEvent = false;
    function clickdown(turl) {
    	var ifr = document.getElementById("downframe");
    	if(!addEvent) {ifr.attachEvent('onload',function(){ifr.contentWindow.document.execCommand('saveas');});addEvent=true;}
    	ifr.src = turl;
    }
</script>
</html>